﻿using System;
using System.Collections.Generic;
using JetBrains.Annotations;
#if NETFX_CORE
using Windows.UI.Xaml.Navigation;
#else
using System.Windows.Navigation;
#endif
using MugenMvvmToolkit.Interfaces;

namespace MugenMvvmToolkit.Models
{
    /// <summary>
    ///     Represents the navigation context.
    /// </summary>
    public class NavigationContext : INavigationContext
    {
        #region Constructors

#if SILVERLIGHT
        /// <summary>
        ///     Initializes a new instance of the <see cref="NavigationContext" /> class.
        /// </summary>
        public NavigationContext(IViewPageMappingItem pageMapping, Uri uri, IDictionary<string, string> parameters, bool isAutoCreatedViewModel, [NotNull] INavigationProvider navigationProvider, NavigationMode? mode)
        {
            Should.NotBeNull(navigationProvider, "navigationProvider");
            if (uri == null && pageMapping != null)
                uri = pageMapping.Uri;
            PageMapping = pageMapping;
            Parameters = parameters;
            Uri = uri;
            IsAutoCreatedViewModel = isAutoCreatedViewModel;
            NavigationProvider = navigationProvider;
            NavigationMode = mode;
        }
#endif

#if WPF
        /// <summary>
        ///     Initializes a new instance of the <see cref="NavigationContext" /> class.
        /// </summary>
        public NavigationContext(IViewPageMappingItem pageMapping, Uri uri, IDictionary<string, string> parameters, object parameter, bool isAutoCreatedViewModel, [NotNull] INavigationProvider navigationProvider, NavigationMode? mode)
        {
            Should.NotBeNull(navigationProvider, "navigationProvider");
            if (uri == null && pageMapping != null)
                uri = pageMapping.Uri;
            PageMapping = pageMapping;
            Parameters = parameters;
            Uri = uri;
            Parameter = parameter;
            IsAutoCreatedViewModel = isAutoCreatedViewModel;
            NavigationProvider = navigationProvider;
            NavigationMode = mode;
        }
#endif

#if NETFX_CORE
        /// <summary>
        ///     Initializes a new instance of the <see cref="NavigationContext" /> class.
        /// </summary>
        public NavigationContext(IViewPageMappingItem pageMapping, object parameter, bool isAutoCreatedViewModel, [NotNull] INavigationProvider navigationProvider, NavigationMode? mode)
        {
            Should.NotBeNull(navigationProvider, "navigationProvider");
            PageMapping = pageMapping;
            if (pageMapping != null)
                Uri = pageMapping.Uri;
            Parameter = parameter;
            IsAutoCreatedViewModel = isAutoCreatedViewModel;
            NavigationProvider = navigationProvider;
            NavigationMode = mode;
        }
#endif

        #endregion

        #region Implementation of INavigationContext

        /// <summary>
        ///     Gets the page mapping, if any.
        /// </summary>
        public IViewPageMappingItem PageMapping { get; private set; }

        /// <summary>
        ///     Gets the uri, if any.
        /// </summary>
        public Uri Uri { get; private set; }

#if !NETFX_CORE
    /// <summary>
    ///     Gets the parameters.
    /// </summary>
        public IDictionary<string, string> Parameters { get; private set; }
#endif

#if NETFX_CORE || WPF
        /// <summary>
        /// A <see cref="T:System.Object"/> that contains data to be used for processing during navigation.
        /// </summary>
        public object Parameter { get; private set; }
#endif
        /// <summary>
        ///     Gets the value that indicates that view-model was created using the navigation system.
        /// </summary>
        public bool IsAutoCreatedViewModel { get; private set; }

        /// <summary>
        ///     Gets or sets the navigation provider.
        /// </summary>
        public INavigationProvider NavigationProvider { get; set; }

        /// <summary>
        /// Gets the value of the mode parameter from the originating Navigate call.
        /// </summary>
        public NavigationMode? NavigationMode { get; private set; }

        #endregion
    }
}